package com.james.customcamera.presenter;

import com.james.customcamera.base.BaseModel;
import com.james.customcamera.base.BasePresenter;
import com.james.customcamera.contract.RegisterContract;
import com.james.customcamera.model.RegisterModel;
import com.james.customcamera.mvp.IModel;
import com.james.customcamera.ui.activity.RegisterActivity;

import java.util.HashMap;

public class RegisterPresenter extends BasePresenter<RegisterActivity> implements RegisterContract.RegisterPresenter {
    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new RegisterModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("register", models[0]);
        return map;
    }


    @Override
    public void register(String userName, String nickName, String password, String repeatPassword) {
        if (!getIView().checkNull() && !getIView().checkPassword()) {
            getIView().showLoading();
            ((RegisterModel) getiModelMap().get("register")).register(userName, password, nickName
                    , new BaseModel.DataListener<String>() {
                        @Override
                        public void successInfo(String result) {
                            getIView().stopLoading();
                            getIView().registerSuccess(result);
                        }

                        @Override
                        public void failInfo(String result) {
                            getIView().stopLoading();
                            getIView().registerFail(result);
                        }
                    });

        }
    }
}
